@extends('template.adminpage')
@section('content')
<script type="text/javascript">
	$(function () {
	    var chart;
	    
	    $(document).ready(function () {
	    	
	    	// Build the chart
	        $('#container').highcharts({
	            chart: {
	                plotBackgroundColor: null,
	                plotBorderWidth: null,
	                plotShadow: false
	            },
	            title: {
	                text: ''
	            },
	            tooltip: {
	        	    pointFormat: '{series.name}: <b>{point.y} order</b>'
	            },
	            plotOptions: {
	                pie: {
	                    allowPointSelect: true,
	                    cursor: 'pointer',
	                    dataLabels: {
	                        enabled: false
	                    },
	                    showInLegend: true
	                }
	            },
	            series: [{
	                type: 'pie',
	                name: 'Sales order kemarin',
	                data: [

	                <?php
	                	foreach($type as $tp){
						$soy = DB::table('sys_order')
								->whereBetween('order_date', array(date('Y-m-d', strtotime('-1 days')).' 00:00:00',date('Y-m-d', strtotime('-1 days')).' 23:59:59'))
								->where('order_name',$tp->order_name)
								->count();
						 if($tp->order_name=='idcard'){$ordername = 'ID Card';}
				        else if($tp->order_name=='packaging'){$ordername = 'Packaging';}
				        else if($tp->order_name=='brochure'){$ordername = 'Brosur';}
				        else if($tp->order_name=='nota'){$ordername = 'Nota';}
				        else if($tp->order_name=='tshirt'){$ordername = 'T-Shirt';} ?>
				       ['{{$ordername}}',{{$soy}}],
					<?php	} ?>
	                ]
	            }]
	        });

// Build the chart
	        $('#container2').highcharts({
	            chart: {
	                plotBackgroundColor: null,
	                plotBorderWidth: null,
	                plotShadow: false
	            },
	            title: {
	                text: ''
	            },
	            tooltip: {
	        	    pointFormat: '{series.name}: <b>{point.y} agen</b>'
	            },
	            plotOptions: {
	                pie: {
	                    allowPointSelect: true,
	                    cursor: 'pointer',
	                    dataLabels: {
	                        enabled: false
	                    },
	                    showInLegend: true
	                }
	            },
	            series: [{
	                type: 'pie',
	                name: 'Jumlah agen',
	                data: [
	                   
	                <?php
	                	foreach($regional as $tp){
						$agenystrd = DB::table('sys_member')
								->whereBetween('member_joindate', array(date('Y-m-d', strtotime('-1 days')).' 00:00:00',date('Y-m-d', strtotime('-1 days')).' 23:59:59'))
								->where('member_regional_id',$tp->member_regional_id)
								->count();
						$reg = DB::table('ref_regional')
								->where('regional_id',$tp->member_regional_id)
								->first();
						?>
				       ['{{$reg->regional_name}}',{{$agenystrd}}],
					<?php	} ?>
	                ]
	            }]
	        });

		

	    	


			$(function () {
		        $('#container3').highcharts({
		            chart: {
		                type: 'column'
		            },
		            title: {
		                text: ''
		            },
		            subtitle: {
		                text: ''
		            },
		            xAxis: {
		                categories: [
						         <?php
						        foreach($bulan as $mn => $mt){
								if($mn<=$b){ ?>
					    			 '{{$mt}}',
					    		<?php	}
					    		}
					    		?>
		                ]
		            },
		            yAxis: {
		                min: 0,
		                title: {
		                    text: 'Order'
		                }
		            },
		            tooltip: {
		                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
		                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
		                    '<td style="padding:0"><b>{point.y} Order</b></td></tr>',
		                footerFormat: '</table>',
		                shared: true,
		                useHTML: true
		            },
		            plotOptions: {
		                column: {
		                    pointPadding: 0.2,
		                    borderWidth: 0
		                }
		            },
		            series: [


		            <?php
		            foreach($produk as $prdk => $val){
	    			echo '{ name: "'.$val.'", ';
	    			echo 'data: [';
			    		foreach($bulan as $mn => $mt){
						$order =  DB::table('sys_order')
								->whereBetween('order_date',array($t.'-'.$mn.'-01 00:00:00', $t.'-'.$mn.'-31 23:59:59'))
								->where('order_name',$prdk)
								->count();
							if($mn<=$b){

					    		echo $order.', ';
					    	}
			    		}
			    	echo ']},';
					}
					?>


		            ]
		        });
		    });
    
			
			$(function () {
		        $('#container4').highcharts({
		            chart: {
		                type: 'column'
		            },
		            title: {
		                text: ''
		            },
		            subtitle: {
		                text: ''
		            },
		            xAxis: {
		                categories: [
		                    <?php
						        foreach($bulan as $mn => $mt){
								if($mn<=$b){ ?>
					    			 '{{$mt}}',
					    		<?php	}
					    		}
					    		?>
		                ]
		            },
		            yAxis: {
		                min: 0,
		                title: {
		                    text: 'Agen'
		                }
		            },
		            tooltip: {
		                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
		                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
		                    '<td style="padding:0"><b>{point.y} Agen</b></td></tr>',
		                footerFormat: '</table>',
		                shared: true,
		                useHTML: true
		            },
		            plotOptions: {
		                column: {
		                    pointPadding: 0.2,
		                    borderWidth: 0
		                }
		            },
		            series: [
		            	<?php
		            	foreach($regionalexist as $region){
		    			echo '{ name: "'.$region->regional_name.'", ';
		    			echo 'data: [';
				    		foreach($bulan as $mn => $mt){
							$regionmonth = DB::table('sys_member')
									->whereBetween('member_joindate', array($t.'-'.$mn.'-01 00:00:00', $t.'-'.$mn.'-31 23:59:59'))
									->where('member_regional_id',$region->regional_id)
									->count();
									if($mn<=$b){
									echo $regionmonth.', ';
						    	}
				    		}
				    	echo ']},';
						}
		            	?>
		            ]
		        });
		    });
    

	    });
	    
	});
</script>

<ol class="breadcrumb">
  <li class="active">Dashboard</li>
</ol>

<div class="container-black">
	<br>

	<div class="row">
		<div class="col-md-10 col-md-offset-1">
  		<h4>Quick shortcut</h4>
			<div class="row">
				<div class="col-md-6">
					<div class="row">
						<div class="col-md-4">
						<a href="{{URL::to('/order/incomingorder')}}"><button class="btn btn-incoming" style="width:150px; height:100px"><span class="fa fa-inbox fa-4x"></span><br>Incoming <span class="badge">{{$in}}</span></button></a>
						</div>
						<div class="col-md-4">
						<a href="{{URL::to('/order/approvingorder')}}"><button class="btn btn-approving" style="width:150px; height:100px"><span class="fa fa-sign-in fa-4x"></span><br>Approving <span class="badge">{{$ap}}</span></button></a>
						</div>
						<div class="col-md-4">
						<a href="{{URL::to('/order/onprocessorder')}}"><button class="btn btn-onprocess" style="width:150px; height:100px"><span class="fa fa-gear fa-4x"></span><br>On Process <span class="badge">{{$on}}</span></button></a>
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="row">
						<div class="col-md-4">
						<a href="{{URL::to('/order/finishedorder')}}"><button class="btn btn-finished" style="width:150px; height:100px"><span class="fa fa-check-square-o fa-4x"></span><br>Finished <span class="badge">{{$fn}}</span></button></a>
						</div>
						<div class="col-md-4">
						<a href="{{URL::to('/order/deliveredorder')}}"><button class="btn btn-delivered" style="width:150px; height:100px"><span class="fa fa-upload fa-4x"></span><br>Delivered <span class="badge">{{$de}}</span></button></a>
						</div>
						<div class="col-md-4">
						<a href="{{URL::to('/order/canceledorder')}}"><button class="btn btn-canceled" style="width:150px; height:100px"><span class="fa fa-undo fa-4x"></span><br>Canceled <span class="badge">{{$ca}}</span></button></a>
						</div>
					</div>
				</div>
			</div>
		
		</div>
  	</div>
  <br>
  <div class="row">
		<div class="col-md-10 col-md-offset-1">
  		<h4>Summary</h4>

			<div class="row">
				<div class="col-md-6">
				<a  data-toggle="modal" data-target="#summarysalesorderkemarin" >
					<button class="btn btn-summarysalesorderkemarin" style="width:470px; height:100px">
						<div class="row">
						<div class="col-md-2 col-md-offset-1">
							<span class="fa fa-suitcase fa-4x"></span>
						</div>
						<div class="col-md-6">
							<label>{{$so}}</label><br>
							 Sales order kemarin
						</div>
						</div>
					</button>
				</a>
				<br>
				<a  data-toggle="modal" data-target="#summarysalesordertotal" >
					<button class="btn btn-summarysalesordertotal" style="width:470px; height:100px">
						<div class="row">
						<div class="col-md-2 col-md-offset-1">
							<span class="fa fa-suitcase fa-4x"></span>
						</div>
						<div class="col-md-6">
							<label>{{$soall}} Order</label><br>
							 Total sales order
						</div>
						</div>
					</button>
				</a>

				</div>
				<div class="col-md-6">
				<a  data-toggle="modal" data-target="#sumarryagenkemarin" >
					<button class="btn btn-sumarryagenkemarin" style="width:470px; height:100px">
						<div class="row">
						<div class="col-md-2 col-md-offset-1">
							<span class="fa fa-user fa-4x"></span>
						</div>
						<div class="col-md-6">
							<label>{{$agen}}</label><br>
							 Agen kemarin
						</div>
						</div>
					</button>
				</a>
				<br>
				<a  data-toggle="modal" data-target="#sumarryagentotal" >
					<button class="btn btn-sumarryagentotal" style="width:470px; height:100px">
						<div class="row">
						<div class="col-md-2 col-md-offset-1">
							<span class="fa fa-users fa-4x"></span>
						</div>
						<div class="col-md-6">
							<label>{{$agenall}} Agen</label><br>
							 Total agen
						</div>
						</div>
					</button>
				</a>

				</div>
			</div>
		
		</div>
  	</div>
<br>
<br>

      

</div>




<div class="modal fade" id="summarysalesorderkemarin" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
<div class="modal-dialog modal-lg">
  <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

    <h4 align="center" class="modal-title"> <label >Summary - Sales order kemarin </label></h4>
    </div>
    <br>
    <div align="left">
              {{Form::open(array(
                    'url' => '/idcard/idcardtype/addidcardtype',
                    'method' => 'POST'
                  ))}}
                <?php
                 if($soy==0){
					echo '<div class="row"><div class="col-md-8 col-md-offset-2"><div class="alert alert-danger" align="center" role="alert">Sales order kemarin kosong</div></div></div>';
				}else{ ?>
				<div id="container" style="min-width: 590px; height: 350px; max-width: 400px;"></div>
				<div class="row">
                <div class="col-md-10 col-md-offset-1">
					<label><u>Detail - Sales order kemarin</u></label>
					<table class="table">
						<tr><th>Jenis order </th><th>Jumlah order</th></tr>
							<?php 
								
								foreach($type as $tp){
								$soym = DB::table('sys_order')
										->whereBetween('order_date', array(date('Y-m-d', strtotime('-1 days')).' 00:00:00',date('Y-m-d', strtotime('-1 days')).' 23:59:59'))
										->where('order_name',$tp->order_name)
										->sum('order_qty');
								
								if($tp->order_name=='idcard'){$ordername = 'ID Card';}
							        else if($tp->order_name=='packaging'){$ordername = 'Packaging';}
							        else if($tp->order_name=='brochure'){$ordername = 'Brosur';}
							        else if($tp->order_name=='nota'){$ordername = 'Nota';}
							        else if($tp->order_name=='tshirt'){$ordername = 'T-Shirt';} 
							    
						     ?> 
						<tr><td>{{$ordername}} </td><td>{{$soym.' '.$tp->order_qty_unit}}</td></tr>
              
				     		<?php } ?>  
               		 </table>        	
                </div>
                </div>
				<?php } ?>  
    </div>
    <div class="modal-footer">

  {{Form::close()}} <button class="btn btn-dark" style="width:125px; margin-right:5px" class="close" data-dismiss="modal">Tutup</button></a>
         
    </div>
  </div>
</div>
</div>

<div class="modal fade" id="summarysalesordertotal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
<div class="modal-dialog modal-lg" style="width:90%">
  <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

    <h4 align="center" class="modal-title"> <label >Sumamary - Total sales order</label></h4>
    </div>
    <br>
    <div align="left">
              {{Form::open(array(
                    'url' => '/idcard/idcardtype/addidcardtype',
                    'method' => 'POST'
                  ))}}
                  <div id="container3" style="min-width: 87%; height: 400px; max-width:100%; margin: 0 auto"></div> 
                  <div class="row">
                <div class="col-md-6 col-md-offset-1">
					<label><u>Detail - Total sales order dari awal tahun</u></label>
					<table class="table">
						<tr><th>Jenis order </th><th>Jumlah order</th></tr>
							<?php 
								foreach($typeall as $tp){
								$soy = DB::table('sys_order')
										->whereBetween('order_date',  array($t.'-01-01 00:00:00', $t.'-'.$b.'-31 23:59:59'))
										->where('order_name',$tp->order_name)
										->sum('order_qty');
								
								if($tp->order_name=='idcard'){$ordername = 'ID Card';}
							        else if($tp->order_name=='packaging'){$ordername = 'Packaging';}
							        else if($tp->order_name=='brochure'){$ordername = 'Brosur';}
							        else if($tp->order_name=='nota'){$ordername = 'Nota';}
							        else if($tp->order_name=='tshirt'){$ordername = 'T-Shirt';} 
						     ?> 
						<tr><td>{{$ordername}} </td><td>{{$soy.' '.$tp->order_qty_unit}}</td></tr>
              
				     		<?php } ?>  
               		 </table>        	
                </div>
                </div>
    
    </div>
    <div class="modal-footer">

   {{Form::close()}} <button class="btn btn-dark" style="width:125px; margin-right:5px" class="close" data-dismiss="modal">Tutup</button></a>
         
    </div>
  </div>
</div>
</div>

<div class="modal fade" id="sumarryagenkemarin" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
<div class="modal-dialog modal-lg">
  <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

    <h4 align="center" class="modal-title"> <label >Summary - Agen kemarin </label></h4>
    </div>
    <br>
    <div align="left">
              {{Form::open(array(
                    'url' => '/idcard/idcardtype/addidcardtype',
                    'method' => 'POST'
                  ))}}
                 <?php
                 if($ageny==0){
					echo '<div class="row"><div class="col-md-8 col-md-offset-2"><div class="alert alert-danger" align="center" role="alert">Tidak ada agen baru kemarin</div></div></div>';
				}else{ ?>
            	<div id="container2" style="min-width: 590px; height: 350px; max-width: 400px;"></div>
            	<div class="row">
                <div class="col-md-10 col-md-offset-1">
					<label><u>Detail - Agen kemarin</u></label>
					<table class="table">
						<tr><th>Kabupaten / Kota </th><th>Jumlah Agen</th></tr>
						<?php
	                	foreach($regional as $tp){
						$agenystrd = DB::table('sys_member')
								->whereBetween('member_joindate', array(date('Y-m-d', strtotime('-1 days')).' 00:00:00',date('Y-m-d', strtotime('-1 days')).' 23:59:59'))
								->where('member_regional_id',$tp->member_regional_id)
								->count();
						$reg = DB::table('ref_regional')
								->where('regional_id',$tp->member_regional_id)
								->first();
						?>
						<tr><td>{{$reg->regional_name}} </td><td>{{$agenystrd}}</td></tr>
					<?php	} ?>
               		 </table>        	
                </div>
                </div>
				<?php } ?>  
    
    </div>
    <div class="modal-footer">

    {{Form::close()}} <button class="btn btn-dark" style="width:125px; margin-right:5px" class="close" data-dismiss="modal">Tutup</button></a>
         
    </div>
  </div>
</div>
</div>

<div class="modal fade" id="sumarryagentotal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
<div class="modal-dialog modal-lg" style="width:90%">
  <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

    <h4 align="center" class="modal-title"> <label >Sumarry - Total agen </label></h4>
    </div>
    <br>
    <div align="left">
              {{Form::open(array(
                    'url' => '/idcard/idcardtype/addidcardtype',
                    'method' => 'POST'
                  ))}}
            

            	<div id="container4" style="min-width: 87%; height: 400px; max-width:100%; margin: 0 auto"></div>
            	<div class="row">
                <div class="col-md-5 col-md-offset-1">
					<label><u>Detail - Total agen dari awal tahun</u></label>
					<table class="table">
						<tr><th>Total agen </th><th>Jumlah Agen</th></tr>
						<?php
						foreach($bulanex as $mn => $mt){
							$regionmonth = DB::table('sys_member')
									->whereBetween('member_joindate', array($t.'-'.$mn.'-01 00:00:00', $t.'-'.$mn.'-31 23:59:59'))
									->count();
									if($mn<=$b){
						    ?>
				    		
						<tr><td>Bulan {{$mt}} </td><td>{{$regionmonth}}</td></tr>
					<?php	} } ?>
               		 </table>        	
                </div>
                <div class="col-md-5">
					<label><u>Detail -Total agen per kabupaten / kota</u></label>
					<table class="table">
						<tr><th>Kabupaten / Kota </th><th>Jumlah Agen</th></tr>
						<?php
	                	foreach($regionalall as $tp){
						$agenystrd = DB::table('sys_member')
								->whereBetween('member_joindate', array($t.'-01-01 00:00:00', $t.'-'.$b.'-31 23:59:59'))
								->where('member_regional_id',$tp->member_regional_id)
								->count();
						$reg = DB::table('ref_regional')
								->where('regional_id',$tp->member_regional_id)
								->first();
						?>
						<tr><td>{{$reg->regional_name}} </td><td>{{$agenystrd}}</td></tr>
					<?php	} ?>
               		 </table>        	
                </div>
                </div>
    
    </div>
    <div class="modal-footer">

    {{Form::close()}} <button class="btn btn-dark" style="width:125px; margin-right:5px" class="close" data-dismiss="modal">Tutup</button></a>
         
    </div>
  </div>
</div>
</div>

@stop
@stop